import * as types from "../types/placeServiceOrderTypes";

const initialState = {
  loading: false,
  initing: true,
  error: undefined,
  facilitySign: "",
  remark: "",
  dateTime: new Date(),
  data: {},
  serviceTypeList: [],
  curServiceWayIndex: 0,
  address: undefined,
};

export default function recycleAccessResultReducer(state = initialState, action) {
  switch (action.type) {
    case types.PLACEORDER_LOADING:
      return {
        ...state,
        loading: true,
      };
    case types.PLACEORDER_INIT:
      return {
        ...state,
        dateTime: new Date(),
        initing: true,
      };
    case types.PLACEORDER_DONE:
      return {
        ...state,
        initing: false,
        loading: false,
        data: action.data,
        facilitySign: action.facilitySign,
        serviceTypeList: action.serviceTypeList,
      };
    case types.PLACESERVICEORDER_DONE:
      return {
        ...state,
        initing: false,
        loading: false,
      };
    case types.PLACEORDER_ERROR:
    case types.PLACESERVICEORDER_ERROR:
      return {
        ...state,
        initing: false,
        loading: false,
        error: action.error,
      };
    case types.PLACEORDER_CHANGE_SERVICEWAY:
      return {
        ...state,
        curServiceWayIndex: action.curServiceWayIndex,
      };
    case types.PLACEORDER_CHANGE_DEFAULTADDRESS:
      return {
        ...state,
        address: action.address,
      };
    case types.PLACEORDER_CHANGE_DATETIME:
      return {
        ...state,
        dateTime: action.dateTime,
      };
    case types.PLACEORDER_CHANGE_REMARK:
      return {
        ...state,
        remark: action.remark,
      };
    case types.PLACEORDER_UNMOUNT:
      return {
        ...initialState,
      };
    default:
      return state;
  }
}
